package it.polimi.swKnights.SWIMv2.servlets.administration;

import it.polimi.swKnights.SWIMv2.ejb.administration.AbilityToApproveRemote;
import it.polimi.swKnights.SWIMv2.servlets.SwimServlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class SeeAbilityProceed
 */
public class SeeAbilityProceed extends SwimServlet
{
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException
	{

		HashMap<String, Boolean> mapAbilitySeenOrNot = new HashMap<String, Boolean>();

		Map<?, ?> params = request.getParameterMap();
		Iterator<?> i = params.keySet().iterator();

		while (i.hasNext())
		{
			String attribName = (String) i.next();
			String attribValue = ((String[]) params.get(attribName))[0];
			
			if (attribName.startsWith("radio_"))
			{

				mapAbilitySeenOrNot.put(attribName.substring(6),
						this.getTruthFromRadio(attribValue));
			}
		}

		AbilityToApproveRemote abApp = this
				.lookUp(AbilityToApproveRemote.class);

		abApp.getAndProcessSeenAbilities(mapAbilitySeenOrNot);
		
		response.sendRedirect("./seeAbilityRequest");

	}

}
